package com.talent.service.impl;

import com.talent.dao.NoticeMapper;
import com.talent.page.Page;
import com.talent.pojo.Notice;
import com.talent.service.NoticeService;
import com.talent.vo.NoticeUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    NoticeMapper noticeMapper;

    @Override
    public Page<NoticeUserVo> selectNoticeUserVoPage(NoticeUserVo noticeUserVo, int currentPage) {
        Page<NoticeUserVo> page = new Page<>(currentPage, Page.DEFAULT_PAGE_SIZE);
        List<NoticeUserVo> list = noticeMapper.selectNoticeUserVoPage(noticeUserVo, page);
        page.setResultList(list);
        return page;
    }

    @Override
    public void addNotice(Notice notice) {
        noticeMapper.insertSelective(notice);
    }

    @Override
    public void deleteAll(String[] ids) {
        noticeMapper.deleteAll(ids);
    }

    @Override
    public void deleteById(Integer id) {
        noticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Notice selectById(Integer id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int editNotice(Notice notice, Integer userId) {
        if(notice.getCreator() != userId){
            return 0;
        }
        return noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    public NoticeUserVo selectNoticeUserVoById(Integer id) {
        return noticeMapper.selectNoticeUserVoById(id);
    }

    @Override
    public int editNoticeUserVo(NoticeUserVo noticeUserVo, Integer id) {
        if(noticeUserVo.getUser().getId() != id){
            return 0;
        }
        return noticeMapper.updateByPrimaryKeyNoticeUserVo(noticeUserVo);
    }
}
